﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Xml;
using SMSSnew.smss_web_reference;


namespace SMSSnew.DATA.CLASSES
{

    public class subjectCLZ
    {
        protected String subject_name;
        protected String subject_code;
        protected int subject_weight;
        protected int total_slots;
        protected String grade_id;

        static smss_web_service_app srv = new smss_web_service_app();
        static readXML XMLreader = new readXML();
      

        public subjectCLZ()
        {
        }

        public subjectCLZ(String subject_name)
        {
            this.subject_name = subject_name;
        }

        public subjectCLZ(String subject_name, String subject_code, int subject_weight, int total_slots, string grade_id)
        {
            this.subject_name = subject_name;
            this.subject_code = subject_code;
            this.subject_weight = subject_weight;
            this.total_slots = total_slots;
            this.grade_id = grade_id;

        }

        public DataTable loadAllSubjectNames()
        {
            DataTable dt;
            string query = "";
            try
            {

                query = XMLreader.readXMLtxt("allSubjectNames", "~/DATA/XML/subjectXML.xml");
                dt = srv.Search(query);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        //.................return no of subject sub types for a particular subject.............
        public int noOfSubTypes(string subjectName)
        {
            DataTable dt;
            string query = "";
            int numberOfSubtypes;

            try
            {

                query = XMLreader.readXMLtxt("getNoOfSubTypes", "~/DATA/XML/subjectXML.xml");
                query = query.Replace("@subjectName", subjectName);

                dt = srv.Search(query);

                numberOfSubtypes = int.Parse(dt.Rows[0][0].ToString());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return numberOfSubtypes;
        }


        //..............returns subject sub types for a particular subject.....................

        public DataTable getSubjectSubTypes(string subjectName)
        {
            DataTable dt;
            string query = "";

            try
            {

                query = XMLreader.readXMLtxt("getSubTypes", "~/DATA/XML/subjectXML.xml");
                query = query.Replace("@subjectName", subjectName);

                dt = srv.Search(query);


            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;

        }

        // for class combination data entry

        public DataTable selectSubjectsWithTypes()
        {
            DataTable dt = new DataTable();

            string query = "";
            srv = new smss_web_service_app();


            query = XMLreader.readXMLtxt("select_subjects_with_types", "~/DATA/XML/subjectXML.xml");
            //   query=Xml


            dt = srv.Search(query);
            return dt;
        }


        public int takeNoOfSlotsForSubject(string grade, string subjectName)
        {
            int slots;
            DataTable dt;
            string query = "";

            try
            {

                query = XMLreader.readXMLtxt("noOfSlotsForSubject", "~/DATA/XML/subjectXML.xml");
                query = query.Replace("@grade", grade);
                query = query.Replace("@subject", subjectName);

                dt = srv.Search(query);

                slots = int.Parse(dt.Rows[0][0].ToString());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return slots;


        }
    }
}

